<template>
  <div class="student-list-page">


    <!-- 操作区域 -->
    <div class="operation-bar">
      <el-input
        v-model="username"
        placeholder="用户名"
        style="width: 200px; margin-right: 10px"
      ></el-input>
      <el-button type="primary" @click="handleQuery">查询</el-button>
      <el-button type="success" @click="handleAdd">添加</el-button>
    </div>

    <!-- 数据表格 -->
    <el-table :data="tableData" border style="width: 100%" class="table">
      <el-table-column prop="id" label="Id"></el-table-column>
      <el-table-column prop="username" label="用户名"></el-table-column>
      <el-table-column prop="realName" label="真实姓名"></el-table-column>
      <el-table-column prop="grade" label="学级"></el-table-column>
      <el-table-column prop="gender" label="性别"></el-table-column>
      <el-table-column prop="phone" label="手机号"></el-table-column>
      <el-table-column prop="createTime" label="创建时间"></el-table-column>
      <el-table-column prop="status" label="状态">
        <template #default="scope">
          <el-tag
            :type="scope.row.status === '启用' ? 'success' : 'info'"
          >{{ scope.row.status }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <el-button
            type="primary"
            size="mini"
            @click="handleEdit(scope.row)"
          >编辑</el-button>
          <el-button
            type="info"
            size="mini"
            @click="handleLog(scope.row)"
          >日志</el-button>
          <el-button
            type="danger"
            size="mini"
            @click="handleDelete(scope.row)"
          >删除</el-button>
          <el-button
            type="warning"
            size="mini"
            @click="handleForbid(scope.row)"
          >禁用</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10, 20, 50]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      class="pagination"
    ></el-pagination>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import {
  ElBreadcrumb,
  ElBreadcrumbItem,
  ElTabs,
  ElTabPane,
  ElInput,
  ElButton,
  ElTable,
  ElTableColumn,
  ElTag,
  ElPagination
} from 'element-plus'

// 模拟表格数据
const tableData = ref([
  {
    id: 104,
    username: 'xjy',
    realName: 'xjy',
    grade: '一年级',
    gender: '男',
    phone: '18888888888',
    createTime: '2025-07-01 11:51:21',
    status: '启用'
  },
  {
    id: 89,
    username: 'gg',
    realName: '1',
    grade: '初一',
    gender: '女',
    phone: '1',
    createTime: '2025-07-01 07:13:28',
    status: '启用'
  },
  {
    id: 86,
    username: 'admin444',
    realName: '123',
    grade: '一年级',
    gender: '男',
    phone: '123',
    createTime: '2023-08-03 11:04:43',
    status: '启用'
  },
  {
    id: 84,
    username: '77777',
    realName: '777',
    grade: '一年级',
    gender: '男',
    phone: '777',
    createTime: '2023-08-03 11:01:46',
    status: '启用'
  },
  {
    id: 83,
    username: '990',
    realName: '666',
    grade: '一年级',
    gender: '男',
    phone: '666',
    createTime: '2023-08-03 11:01:04',
    status: '启用'
  },
  {
    id: 81,
    username: '11',
    realName: 'yy',
    grade: '六年级',
    gender: '男',
    phone: '15200000000',
    createTime: '2023-08-03 10:33:12',
    status: '启用'
  },
  {
    id: 24,
    username: 'dingjiantao',
    realName: '学生',
    grade: '高三',
    gender: '男',
    phone: '',
    createTime: '2022-12-15 06:10:41',
    status: '启用'
  },
  {
    id: 23,
    username: 'QinZhan',
    realName: '学生',
    grade: '高二',
    gender: '男',
    phone: '17777777777',
    createTime: '2022-12-15 06:10:37',
    status: '启用'
  },
  {
    id: 22,
    username: 'liruhong',
    realName: '学生',
    grade: '一年级',
    gender: '男',
    phone: '',
    createTime: '2022-12-15 06:10:36',
    status: '启用'
  },
  {
    id: 21,
    username: 'kongxianglong',
    realName: '学生',
    grade: '高三',
    gender: '男',
    phone: '',
    createTime: '2022-12-15 06:10:36',
    status: '启用'
  }
])
const username = ref('')
const activeTab = ref('student')
const currentPage = ref(1)
const pageSize = ref(10)
const total = ref(tableData.value.length)

// 查询事件
const handleQuery = () => {
  console.log('查询条件：', username.value)
  // 可结合接口实现真实查询逻辑
}

// 添加事件
const handleAdd = () => {
  console.log('点击添加')
  // 可跳转到添加页面或弹出添加弹窗
}

// 编辑事件
const handleEdit = (row) => {
  console.log('编辑行数据：', row)
  // 可跳转到编辑页面，传递 row 数据
}

// 日志事件
const handleLog = (row) => {
  console.log('查看日志：', row)
  // 可跳转到日志页面或弹出日志弹窗
}

// 删除事件
const handleDelete = (row) => {
  console.log('删除行数据：', row)
  // 调接口删除，然后更新 tableData
  tableData.value = tableData.value.filter(item => item.id!== row.id)
  total.value = tableData.value.length
}

// 禁用事件
const handleForbid = (row) => {
  console.log('禁用行数据：', row)
  row.status = row.status === '启用'? '禁用' : '启用'
}

// 分页事件
const handleSizeChange = (val) => {
  pageSize.value = val
  // 调接口获取对应条数数据
}
const handleCurrentChange = (val) => {
  currentPage.value = val
  // 调接口获取对应页数据
}
</script>

<style scoped>
.student-list-page {
  padding: 20px;
  background-color: #fff;
}
.breadcrumb {
  margin-bottom: 16px;
}
.tabs {
  margin-bottom: 16px;
}
.operation-bar {
  margin-bottom: 16px;
}
.table {
  margin-bottom: 16px;
}
.pagination {
  text-align: right;
}
</style>
